package applet;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;

public class SoundPlay {
	Thread thread;

	public void init() {
		thread = new Thread(new SoundThread());
		thread.start();
	}

	public static void main(String args[]) {
		SoundPlay sp = new SoundPlay();
		sp.init();
	}

	class SoundThread implements Runnable {
		AudioClip audioClip;
		File audioFile;

		public SoundThread() {
			super();
			audioFile = new File("D:\\Users\\jingxin\\Music\\AU_file\\alarm.au");
			try {
				audioClip = Applet.newAudioClip(audioFile.toURL());
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
		}

		public void run() {
			for (int i = 0; i < 100000; i++) {
				if (i % 1000 == 0) {
					System.out.println(i);
					audioClip.play();
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
